using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
using System;

public class DoubleClickBtn : Button
{
    private ButtonClickedEvent _onDoubleClick;
    private Action _onPointerEnter;
    private Action _onPointerExit;

    public ButtonClickedEvent onDoubleClick
    {
        get { return _onDoubleClick; }
        set { _onDoubleClick = value; }
    }

    public Action onPointerEnter
    {
        get { return _onPointerEnter; }
        set { _onPointerEnter = value; }
    }

    public Action onPointerExit
    {
        get { return _onPointerExit; }
        set { _onPointerExit = value; }
    }

    protected DoubleClickBtn()
    {
        _onDoubleClick = new ButtonClickedEvent();
    }

    public override void OnPointerEnter(PointerEventData eventData)
    {
        if (!interactable) return;

        base.OnPointerEnter(eventData);
        if (onPointerEnter != null)
            onPointerEnter.Invoke();
    }

    public override void OnPointerExit(PointerEventData eventData)
    {
        if (!interactable) return;

        base.OnPointerExit(eventData);
        if (onPointerExit != null)
            onPointerExit.Invoke();
    }

    public override void OnPointerClick(PointerEventData eventData)
    {
        if (eventData.clickCount == 2)
        {
            if (_onDoubleClick != null)
                _onDoubleClick.Invoke();
        }
        else
        {
            if (onClick != null)
                onClick.Invoke();
        }

    }
}
